package iv1201project.view;

import java.io.Serializable;
import java.util.Locale;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.inject.Named;

/**
 * Responsible for handling user language selection.
 */
@Named("languagebean")
@ManagedBean
@SessionScoped
public class LanguageManager implements Serializable {

    private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

    /**
     * @return The locale object.
     */
    public Locale getLocale() {
        return locale;
    }

    /**
     * @return The locale language.
     */
    public String getLanguage() {
        return locale.getLanguage();
    }

    /**
     * Set the language.
     * 
     * @param language The language to be set.
     */
    public void setLanguage(String language) {
        locale = new Locale(language);
        FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
    }
}